{{- $page := .page -}}
{{- $self := .self -}}
{{- $name := .Name -}}
{{- $site := .Site -}}
{{- $page_scratch := .page_scratch -}}

{{- $page_scratch.Set "tmp_items" (where ($page.Resources.Match (printf "%s/*.md" (strings.TrimSuffix "/index" $name))) ".Name" "ne" $self.Name) -}}

{{- if eq (len ($page_scratch.Get "tmp_items")) 0 -}}
  {{- range $directory := ($page_scratch.Get "fragment_directories") -}}
    {{- if eq (len ($page_scratch.Get "tmp_items")) 0 -}}
      {{- $page_scratch.Set "tmp_items" (where ($directory.Resources.Match (printf "%s/*.md" $name)) ".Name" "ne" $self.Name) -}}
    {{- end -}}
  {{- end -}}
{{- end -}}

{{- $page_scratch.Set "tmp_subitems" slice -}}
{{- range ($page_scratch.Get "tmp_items") -}}
  {{- if not .Params.disabled -}}
    {{- $page_scratch.Add "tmp_subitems" (dict "Name" (replaceRE "[\\/\\.]" "-" .Name) "Params" .Params "File" .File "ResourceType" .ResourceType "Title" .Title "Permalink" .Permalink "RelPermalink" .RelPermalink "Content" .Content "MediaType" .MediaType "MediaType.MainType" .MediaType.MainType "MediaType.SubType" .MediaType.SubType "MediaType.Suffixes" .MediaType.Suffixes) -}}
  {{- end -}}
{{- end -}}

{{- return ($page_scratch.Get "tmp_subitems") -}}
